﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;    // needed for Description Attributes/PropertyGrid
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.IO.IsolatedStorage;
using System.Runtime.Serialization;

namespace ContinuumSL.Classes
{
    public class ContinuumSettings
    {
        private string _ActiveUniverse = "";
        [Description("The last opened universe")]
        public string ActiveUniverse { get { return _ActiveUniverse; } set { _ActiveUniverse = value; } }

        #region Save/Load Universe

        public static ContinuumSettings LoadSettings(string Filename)
        {
			var store = IsolatedStorageFile.GetUserStoreForApplication();
			
			if (!store.FileExists(Filename)) return null;
			
            ContinuumSettings newSettings;

            XmlSerializer s = new XmlSerializer(typeof(ContinuumSettings));
            //TextReader r = new StreamReader(Filename);
			IsolatedStorageFileStream isfs = store.OpenFile(Filename, FileMode.Open);
            newSettings = (ContinuumSettings)s.Deserialize(isfs);
            isfs.Close();

            return newSettings;
        }

        public void SaveSettings(string Filename)
        {
			var store = IsolatedStorageFile.GetUserStoreForApplication();
			
            XmlSerializer s = new XmlSerializer(typeof(ContinuumSettings));
            //TextWriter w = new StreamWriter(Filename);
			IsolatedStorageFileStream isfs = store.OpenFile(Filename, FileMode.Create);

			s.Serialize(isfs, this);
            isfs.Close();
        }

        #endregion

    }
}
